package j2;
import java.util.Random;
import java.util.Scanner;

public class javs2 {
    public static void main(String[] args) {
        int a, b,v;
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        System.out.println("生成多少道计算题:");
        v=sc.nextInt();
        a = v+1;
        while (a > v) {
            System.out.println("生成多少道加法题:");
            System.out.println("-------------");
            a = sc.nextInt();
            if (a > v) {
                System.out.println("习题太多了请重新输入：");
            }
        }
        b = v - a;
        String[] e = new String[v+1];
        String[] f = new String[v+1];
        String[] g = new String[v+1];
        String[] c = new String[a];
        String[] d = new String[b];
        System.out.println("-------------");
        for (int i = 0; i < a; i++) {
            c[i] = jsub.s1();
            for (int j = 0; j < i; j++) {
                if (c[i].equals(c[j])) {
                    c[i] = null;
                    i--;
                    break;
                }
            }
        }
        for (int i = 0; i < b; i++) {
            d[i] = jsub.s2();
            for (int j = 0; j < i; j++) {
                if (d[i].equals(d[j])) {
                    d[i] = null;
                    i--;
                    break;
                }
            }
        }
        for (int i = 0; i < a; i++) {
            e[i] = c[i];
        }
        for (int i = 0; i < b; i++) {
            e[a + i] = d[i];
        }
        for (int i = 1; i <= a + b; i++) {

            System.out.printf("(%3d)" + e[i - 1].substring(0, 9) + "  ", i);
            if (i % 5 == 0) {
                System.out.println();
                System.out.println("-------------");
            }
        }
        System.out.println("-------------");
        int x = 51;
        while (x > 50){
            System.out.println("请说出需随机抽出多少题练习（最多50题）：");
            x = sc.nextInt();
            if (x > 50) {
                System.out.println("习题太多了请重新输入：");
            } else {
                for (int i = 0; i < x; i++) {
                    int x1 = random.nextInt(50);
                    f[i] = e[x1];
                    g[i] = e[x1].substring(12);
                    for (int j = 0; j < i; j++) {
                        if (f[i].equals(f[j])) {
                            f[i] = null;
                            i--;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println("习题：");
        System.out.println("-------------");
        double h = (double) 1 / x;
        double h1 = 0;
        for (int i = 0; i < x; i++) {
            System.out.println(f[i].substring(0, 12) + "???");
            String x2 = String.format("%3s", sc.next());
            if (x2.equals("uno")) {
                break;
            } else if (x2.equals(g[i])) {
                System.out.println("恭喜你答对了！");
                h1 += h;
            } else {
                System.out.println("答错了,正确答案是" + g[i]);
                A[j] = f[i];
                j++;
            }
        }
        System.out.println("-------------");
        System.out.printf("本次练习的正确率为%.2f%%", h1 * 100);
        jsub.sE(A,j);
    }
    private static String[] A = new String[50];
    private static int j = 0;
}

